home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kio / progressbase.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  7.4 KB  |  272 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 2000 Matej Koss <koss@miesto.sk>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.    Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef __progressbase_h__
  19. #define __progressbase_h__
  20.  
  21.  
  22. #include <qwidget.h>
  23.  
  24. #include <kio/global.h>
  25.  
  26. class KURL;
  27. namespace KIO {
  28.   class Job;
  29.   class CopyJob;
  30.   class DeleteJob;
  31. }
  32.  
  33. namespace KIO
  34. {
  35.   enum Progress {
  36.     DEFAULT = 1,
  37.     STATUSBAR = 2,
  38.     LIST = 3
  39.   };
  40.  
  41. /**
  42. * This class does all initialization stuff for progress,
  43. * like connecting signals to slots.
  44. * All slots are implemented as pure virtual methods.
  45. *
  46. * All custom IO progress dialog should inherit this class.
  47. * Add your GUI code to the constructor and implemement those virtual
  48. * methods which you need in order to display progress.
  49. *
  50. * E.g. StatusbarProgress only implements slotTotalSize(),
  51. * slotPercent() and slotSpeed().
  52. *
  53. * Custom progress dialog will be used like this :
  54. * \code
  55. * // create job
  56. * CopyJob* job = KIO::copy(...);
  57. * // create a dialog
  58. * MyCustomProgress *customProgress;
  59. * customProgress = new MyCustomProgress();
  60. * // connect progress with job
  61. * customProgress->setJob( job );
  62. * ...
  63. * \endcode
  64. *
  65. * There is a special method setStopOnClose() that controls the behavior of
  66. * the dialog.
  67. * @short Base class for IO progress dialogs.
  68. * @author Matej Koss <koss@miesto.sk>
  69. */
  70. class KIO_EXPORT ProgressBase : public QWidget {
  71.  
  72.   Q_OBJECT
  73.  
  74. public:
  75.  
  76.   /**
  77.    * Creates a new progress dialog.
  78.    * @param parent the parent of this dialog window, or 0
  79.    */
  80.   ProgressBase( QWidget *parent );
  81.   ~ProgressBase() {}
  82.  
  83.   /**
  84.    * Assign a KIO::Job to this progress dialog.
  85.    * @param job the job to assign
  86.    */
  87.   void setJob( KIO::Job *job );
  88.   /**
  89.    * Assign a KIO::Job to this progress dialog.
  90.    * @param job the job to assign
  91.    */
  92.   void setJob( KIO::CopyJob *job );
  93.   /**
  94.    * Assign a KIO::Job to this progress dialog.
  95.    * @param job the job to assign
  96.    */
  97.   void setJob( KIO::DeleteJob *job );
  98.  
  99.   // should we stop the job when the dialog is closed ?
  100.   void setStopOnClose( bool stopOnClose ) { m_bStopOnClose = stopOnClose; }
  101.   bool stopOnClose() const { return m_bStopOnClose; }
  102.  
  103.   // should we delete the dialog or just clean it when the job is finished ?
  104.   /**
  105.    * This controls whether the dialog should be deleted or only cleaned when
  106.    * the KIO::Job is finished (or canceled).
  107.    *
  108.    * If your dialog is an embedded widget and not a separate window, you should
  109.    * setOnlyClean(true) in the constructor of your custom dialog.
  110.    *
  111.    * @param onlyClean If true the dialog will only call method slotClean.
  112.    * If false the dialog will be deleted.
  113.    * @see onlyClean()
  114.    */
  115.   void setOnlyClean( bool onlyClean ) { m_bOnlyClean = onlyClean; }
  116.  
  117.   /**
  118.    * Checks whether the dialog should be deleted or cleaned.
  119.    * @return true if the dialog only calls slotClean, false if it will be
  120.    *         deleted
  121.    * @see setOnlyClean()
  122.    */
  123.   bool onlyClean() const { return m_bOnlyClean; }
  124.  
  125.   /**
  126.    * Call when the operation finished.
  127.    * @since 3.1
  128.    */
  129.   void finished();
  130.  
  131. public slots:
  132.   /**
  133.    * This method should be called for correct cancellation of IO operation
  134.    * Connect this to the progress widgets buttons etc.
  135.    */
  136.   void slotStop();
  137.   /**
  138.    * This method is called when the widget should be cleaned (after job is finished).
  139.    * redefine this for custom behavior.
  140.    */
  141.   virtual void slotClean();
  142.  
  143.   // progress slots
  144.   /**
  145.    * Called to set the total size.
  146.    * @param job the KIO::Job
  147.    * @param size the total size in bytes
  148.    */
  149.   virtual void slotTotalSize( KIO::Job* job, KIO::filesize_t size ) {
  150.     Q_UNUSED(job);Q_UNUSED(size);}
  151.   /**
  152.    * Called to set the total number of files.
  153.    * @param job the KIO::Job
  154.    * @param files the number of files
  155.    */
  156.   virtual void slotTotalFiles( KIO::Job* job, unsigned long files ) {
  157.     Q_UNUSED(job);Q_UNUSED(files);}
  158.   /**
  159.    * Called to set the total number of directories.
  160.    * @param job the KIO::Job
  161.    * @param dirs the number of directories
  162.    */
  163.   virtual void slotTotalDirs( KIO::Job* job, unsigned long dirs ) {
  164.     Q_UNUSED(job);Q_UNUSED(dirs);}
  165.  
  166.   /**
  167.    * Called to set the processed size.
  168.    * @param job the KIO::Job
  169.    * @param bytes the processed size in bytes
  170.    */
  171.   virtual void slotProcessedSize( KIO::Job* job, KIO::filesize_t bytes ) {
  172.     Q_UNUSED(job);Q_UNUSED(bytes);}
  173.   /**
  174.    * Called to set the number of processed files.
  175.    * @param job the KIO::Job
  176.    * @param files the number of files
  177.    */
  178.   virtual void slotProcessedFiles( KIO::Job* job, unsigned long files ) {
  179.     Q_UNUSED(job);Q_UNUSED(files);}
  180.   /**
  181.    * Called to set the number of processed directories.
  182.    * @param job the KIO::Job
  183.    * @param dirs the number of directories
  184.    */
  185.   virtual void slotProcessedDirs( KIO::Job* job, unsigned long dirs ) {
  186.     Q_UNUSED(job);Q_UNUSED(dirs);}
  187.  
  188.   /**
  189.    * Called to set the speed.
  190.    * @param job the KIO::Job
  191.    * @param speed the speed in bytes/second
  192.    */
  193.   virtual void slotSpeed( KIO::Job* job, unsigned long speed ) {
  194.     Q_UNUSED(job);Q_UNUSED(speed);}
  195.  
  196.   /**
  197.    * Called to set the percentage.
  198.    * @param job the KIO::Job
  199.    * @param percent the percentage
  200.    */
  201.   virtual void slotPercent( KIO::Job* job, unsigned long percent ) {
  202.     Q_UNUSED(job);Q_UNUSED(percent);}
  203.  
  204.   /**
  205.    * Called when the job is copying.
  206.    * @param job the KIO::Job
  207.    * @param src the source of the operation
  208.    * @param dest the destination of the operation
  209.    */
  210.   virtual void slotCopying( KIO::Job* job, const KURL& src, const KURL& dest ) {
  211.     Q_UNUSED(job);Q_UNUSED(src);Q_UNUSED(dest);}
  212.   /**
  213.    * Called when the job is moving.
  214.    * @param job the KIO::Job
  215.    * @param src the source of the operation
  216.    * @param dest the destination of the operation
  217.    */
  218.   virtual void slotMoving( KIO::Job* job, const KURL& src, const KURL& dest ) {
  219.     Q_UNUSED(job);Q_UNUSED(src);Q_UNUSED(dest);}
  220.   /**
  221.    * Called when the job is deleting.
  222.    * @param job the KIO::Job
  223.    * @param url the URL to delete
  224.    */
  225.   virtual void slotDeleting( KIO::Job* job, const KURL& url) {
  226.     Q_UNUSED(job);Q_UNUSED(url);}
  227.   /**
  228.    * Called when the job is creating a directory.
  229.    * @param job the KIO::Job
  230.    * @param dir the URL of the directory to create
  231.    */
  232.   virtual void slotCreatingDir( KIO::Job* job, const KURL& dir ) {
  233.     Q_UNUSED(job);Q_UNUSED(dir);}
  234.  
  235.   /**
  236.    * Called when the job is resuming..
  237.    * @param job the KIO::Job
  238.    * @param from the position to resume from in bytes
  239.    */
  240.   virtual void slotCanResume( KIO::Job* job, KIO::filesize_t from) {
  241.     Q_UNUSED(job);Q_UNUSED(from);}
  242.  
  243. signals:
  244.   /**
  245.    * Called when the operation stopped.
  246.    */
  247.   void stopped();
  248.  
  249. protected slots:
  250.   void slotFinished( KIO::Job* );
  251.  
  252. protected:
  253.  
  254.   virtual void closeEvent( QCloseEvent * );
  255.  
  256.   KIO::Job* m_pJob;
  257.  
  258. private:
  259.   bool m_bOnlyClean;
  260.   bool m_bStopOnClose;
  261.  
  262.  
  263. protected:
  264.     virtual void virtual_hook( int id, void* data );
  265. private:
  266.     class ProgressBasePrivate* d;
  267. };
  268.  
  269. } /* namespace */
  270.  
  271. #endif // __progressbase_h__
  272.